//#include<iostream>
//typedef long long ll;
//using namespace std;
//ll quick_pow(ll a, ll b, ll p)
//{
//	ll ret = 1;
//	while (b)
//	{
//		if (b & 1) ret = ret * a;
//		a = a * a;
//		b >>= 1;
//	}
//	return ret;
//}
//int main()
//{
//	ll a, b, p;
//	cin >> a >> b >> p;
//	cout << a << "^" << b << ' ' << "mod" << ' ' << p << "=" << quick_pow(a, b, p);
//	return 0;
//}
#include<iostream>
using namespace std;
typedef long long ll;
ll quick_pow(ll a, ll b, ll p)
{
	ll ret = 1;
	while (b)
	{
		if (b & 1) ret = ret * a % p;
		a = a * a % p;
		b >>= 1;
	}
	return ret;
}
int main()
{
	int a, b, p;cin >> a >> b >> p;
	cout << a << "^" << b << " " << "mod" << ' ' << p << "=" << quick_pow(a, b, p);
	return 0;
}
